// 用户请求
import pyAxios from "./http";

//登录
async function login(userData) {
    try {
        const response = await pyAxios({
            method: 'post',
            url: '/user/login',
            data: userData
        })
        return response;
    } catch (error) {
        console.log(error);

    }
}
//发送验证码
async function sendVerifyCode(email, codeType) {
    try {
        const response = await pyAxios({
            method: 'get',
            url: '/user/verifyCode',
            params: {
                email: email,
                codeType: codeType
            }

        })
        return response;
    } catch (error) {
        console.log(error);

    }

}
// 注册
async function register(userData) {
    try {
        const response = await pyAxios({
            method: 'post',
            url: '/user/register',
            data: userData
        })
        return response;
    } catch (error) {
        console.log(error);

    }
}
//修改密码
async function alterPassword(userData) {
    try {
        const response = await pyAxios({
            method: 'post',
            url: '/user/updatePassword',
            data: userData
        })
        return response;
    } catch (error) {
        console.log(error);

    }
}

//获取自己收到的通知
async function getMyInform(userId) {
    try {
        const response = await pyAxios({
            method:'get',
            url:'/user/getMyInform',
            params:{
                userId
            }
        })
        return response;
    } catch (error) {
        console.log(error);
        
    }   
}


//删除通知
async function deleteInform(informId) {
    try {
        const response = await pyAxios({
            method:'delete',
            url:'/user/deleteInform',
            params:{
                informId
            }
        })

        return response;
    } catch (error) {
        console.log(error);  
    }   
}

//申请成为教师
async function upApplyText(from) {
    try {
        const response = await pyAxios({
            method: 'post',
            url: '/user/upApplyText',
            data: from
        })
        return response;
    } catch (error) {
        console.log(error);
    }
}

//获取自己收到的通知
async function getCourseList() {
    try {
        const response = await pyAxios({
            method:'get',
            url:'/user/getCourseList',
        })
        return response;
    } catch (error) {
        console.log(error);
    }   
}

//获取自己收到的通知
async function getCourseChapter(courseId) {
    try {
        const response = await pyAxios({
            method:'get',
            url:'/user/getCourseChapter',
            params:{courseId}
        })
        return response;
    } catch (error) {
        console.log(error);
        
    }   
}
//获取自己收到的通知
async function getEditorDataById(chapterId) {
    try {
        const response = await pyAxios({
            method:'get',
            url:'/user/getEditorDataById',
            params:{chapterId}
        })
        return response;
    } catch (error) {
        console.log(error);
        
    }   
}

//获取自己收到的通知
async function getUserInfo(userId) {
    try {
        const response = await pyAxios({
            method:'get',
            url:'/user/getUserInfo',
            params:{userId}
        })
        return response;
    } catch (error) {
        console.log(error);
        
    }   
}

//获取自己收到的通知
async function getChatHistory(fromUserId,toUserId) {
    try {
        const response = await pyAxios({
            method:'get',
            url:'/user/getChatHistory',
            params:{fromUserId,toUserId}
        })
        return response;
    } catch (error) {
        console.log(error);
        
    }   
}

//获取用户课程
async function getUserCourseList(userId,role) {
    try {
        const response = await pyAxios({
            method:'get',
            url:'/user/getUserCourseList',
            params:{userId,role}
        })
        return response;
    } catch (error) {
        console.log(error);
        
    }   
}


export default {getUserCourseList, getChatHistory,getUserInfo,getEditorDataById,getCourseChapter,getCourseList,upApplyText,deleteInform,getMyInform,login, sendVerifyCode, register, alterPassword }